#include <stdio.h>
#include "byteorder_swap.h"

#pragma pack(1)
typedef struct {
	int n;
	short h[2];
} a_t;

typedef struct {
	int n;
	a_t a;
} b_t;

typedef struct {
	char b1;
	a_t a[2];
	short h;
} c_t;

#pragma pack()

void test()
{
	int size;
	c_t c = {1, {{0x12345678, {0x1122, 0x3344}},{0x98765432, {0x9988, 0x7766}}}, 0x5566};
	fmt_node_t *tree;
	tree = fmt_node_init("b2{n2h}h");
	dump_fmt_tree(tree, 0);
	printf("b1:%hhx, a{{n:%x, h[0]:%hx, h[1]:%hx},{n:%x, h[0]:%hx, h[1]:%hx}}, h:%hx\n",
			c.b1, c.a[0].n, c.a[0].h[0], c.a[0].h[1], c.a[1].n, c.a[1].h[0], c.a[1].h[1], c.h);
	size = swap_byteorder(&c, tree);
	printf("size:%d\n", size);
	printf("b1:%hhx, a{{n:%x, h[0]:%hx, h[1]:%hx},{n:%x, h[0]:%hx, h[1]:%hx}}, h:%hx\n",
		   c.b1, c.a[0].n, c.a[0].h[0], c.a[0].h[1], c.a[1].n, c.a[1].h[0], c.a[1].h[1], c.h);
}


int main() {

	test();

	return 0;
}
